﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ComicsEditor
{
    public class WriterFolder : IComicWriter
    {
        public readonly string FolderPath;

        public WriterFolder(string FolderPath)
        {
            this.FolderPath = FolderPath;
        }

        public void AddStream(string key, Stream stream)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(FolderPath + Path.DirectorySeparatorChar + key));
            using (FileStream fs = File.Open(FolderPath + Path.DirectorySeparatorChar + key, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
            {
                byte[] buffer = new byte[65536];
                int read;
                while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                    fs.Write(buffer, 0, read);
                fs.SetLength(fs.Position);
            }
        }

        public void Close()
        {
        }
    }
}
